<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jsps/tag.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>菜单管理</title>
<%@ include file="/WEB-INF/jsps/common_css.jsp"%>
<%@ include file="/WEB-INF/jsps/common_js.jsp"%>

<script type="text/javascript">

$(function(){
	
	$('#menu_list_id').datagrid({    
	    url:'${baseurl}menu/list',
	    toolbar:"#menu_toolbar_id"
	});
	
	
	//新增
	$("#menu_add_id").click(function(){
		$('#parentId').combobox('reload');      
		$("#parentId").combobox("select",1);
		$("#menu_edit_id").dialog("open");
	});
	
	//取消
	$("#menu_edit_dialog_buttons_cancel_id").click(function(){
		$("#menu_edit_id").dialog("close");
		$('#menu_form_id').form("clear");
	});
	

 	//提交表单
	$("#menu_edit_dialog_buttons_ok_id").click(function(){
		if(!$('#menu_form_id').form("validate")){
			return;
		}
		
		var id = $("#id").val();
		var name = $("#menu_name_id").val();
		
		$.post("${baseurl}menu/update", { "id":id,"name":name},
			 function(data){
			  if(data.success){
		        	$('#menu_list_id').datagrid("reload");
		        	$('#menu_form_id').form("clear");
		        	$.messager.show({title:'系统提示',msg:data.content,timeout:5000,showType:'slide'});
		        }
			    $("#menu_edit_id").dialog("close");
			    $.messager.show({title:'操作失败',msg:data.content,timeout:5000,showType:'slide'});
			  }
			 ,"json"); 
	});
	
	
	//删除
	$("#menu_delete_id").click(function(){
		var selected =  $("#menu_list_id").datagrid("getSelected");
		if(selected == null){
			alert("请选中你要删除的记录.");
		}else{
			$.post("${baseurl}menu/delete", { "id":selected.id},
					   function(data){
					    	if(data.success){
					    		$('#menu_list_id').datagrid("reload");
					    		$.messager.show({title:'系统提示',msg:data.content,timeout:5000,showType:'slide'});
					    	}else{
					    		$('#menu_form_id').form("clear");
					    		$.messager.alert('警告',data.content); 
					    	}
					   }, "json");
		}
	});
	
	
	//修改
	$("#menu_update_id").click(function(){
		var selected =  $("#menu_list_id").datagrid("getSelected");
		if(selected == null){
			alert("请选中你要修改的记录.");
		}else{
			$('#menu_form_id').form("load","${baseurl}menu/get?id="+selected.id);
			$("#id").val(selected.id);
			$("#menu_edit_id").dialog("open");
		}
	});
	
	
	
});
	
</script>
</head>
<body>
	<table id="menu_list_id" style="width:100%;height:99%;"
		data-options="fitColumns:true,singleSelect:true,pagination:true,pagePosition:'bottom'">   
	    <thead>   
	        <tr>   
	            <th data-options="field:'id',width:20">id</th>   
	            <th data-options="field:'name',width:20">菜单名</th>
              	<th data-options="field:'parentName',width:20">上级菜单</th>
	        </tr>   
	    </thead>   
	</table>
	
	<!-- 数据表格toolbar -->
	<div id="menu_toolbar_id">
<!-- 		<a id="menu_add_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新增 </a> -->
		<a id="menu_update_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>
		<a id="menu_delete_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
	</div>
	
	<!-- 编辑对话框 -->
	<div id="menu_edit_id" class="easyui-dialog" title="用户管理" style="width:300px;height:150px"   
        data-options="iconCls:'icon-save',modal:true,closed:true,buttons:'#menu_edit_dialog_buttons_id'">   
   		<form id="menu_form_id" method="post">
   			<input id="id" type="hidden" name="id"/>
   			<table>
   				<tr>
   					<td>
   						<div>   
					        <label for="name">菜单名称:</label>   
					        <input id="menu_name_id" class="easyui-validatebox" type="text" name="name" data-options="required:true" />
					    </div> 
   					</td>
   				</tr>
<!--    				<tr> -->
<!--    					<td> -->
<!--    						<div>    -->
<!-- 					        <label for="menuname">菜单图标:</label>    -->
<!-- 					          <input id="menu_icon" class="easyui-combobox" name="icon"    -->
<%--     								data-options="valueField:'id',textField:'name',url:'${baseurl}menu/all',editable:false" />   --%>
<!-- 					    </div>  -->
<!--    					</td> -->
<!--    				</tr> -->
   			</table>
		</form>
	</div>
	
	<!-- 编辑对话框的buttons -->
	<div id="menu_edit_dialog_buttons_id">
		<a id="menu_edit_dialog_buttons_ok_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">保存</a>
		<a id="menu_edit_dialog_buttons_cancel_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">关闭</a>
	</div>
	
</body>
</html>